#pragma once
#include "Protocol.hpp"
enum
{
    Success = 0,
    DivZoreError,
    ModZoreError,
    UnkownOper,
};
class Calculate
{
public:
    std::shared_ptr<Protocol::Response> Cal(std::shared_ptr<Protocol::Request> req)
    {
        std::shared_ptr<Protocol::Response> resp = _factory.BuildResponse();
        resp->Setcode(Success);
        switch (req->GetOp())
        {
        case '+':
            resp->SetResult(req->GetX() + req->GetY());
            break;
        case '-':
            resp->SetResult(req->GetX() - req->GetY());
            break;
        case '*':
            resp->SetResult(req->GetX() * req->GetY());
            break;

        case '/':
        {
            if (req->GetY() == 0)
            {
                resp->Setcode(DivZoreError);
            }
            else
            {
                resp->SetResult(req->GetX() / req->GetY());
            }
        }
        break;
        case '%':
        {
            if (req->GetY() == 0)
            {
                resp->Setcode(ModZoreError);
            }
            else
            {
                resp->SetResult(req->GetX() %req->GetY());
            }
        }
        break;
        default:
            resp->Setcode(UnkownOper);
            break;
        }
        return resp;
    }

private:
    Protocol::Factory _factory;
};